package org.zhxy.zhxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.zhxy.zhxy.dao.NoticeDao;
import org.zhxy.zhxy.entity.Notice;
import org.zhxy.zhxy.service.NoticeService;

import javax.annotation.Resource;
import java.util.List;


/**
 * 项目名称: zhxy
 * 作者: zhaojs
 * 创建日期: 2024年10月20日
 * 文件说明: 见类描述
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeDao, Notice> implements NoticeService {

    @Resource
    private NoticeDao noticeDao;

    @Override
    public List<Notice> selectList() {
        QueryWrapper<Notice> noticeQueryWrapper = new QueryWrapper<>();
        noticeQueryWrapper.orderByDesc("create_time");
        List<Notice> notices = noticeDao.selectList(noticeQueryWrapper);
        List<Notice> notices1 = notices.subList(0, 10);
        return notices1;
    }

    /**
     * 查询公告列表
     * @param page
     * @param pageSize
     */
    @Override
    public Page<Notice> listNotice(int page, int pageSize) {
        int offset = (page - 1) * pageSize;
        List<Notice> notices = noticeDao.selectNotices(offset, pageSize);

        Page<Notice> noticePage = new Page<>();
        noticePage.setTotal(noticeDao.countNotices());
        noticePage.setRecords(notices);

        return noticePage;
    }
}
